package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.favorDTO;
import com.example.musicwebcon.model.favorSong;
import com.example.musicwebcon.service.serviceInterface.IfavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController //返回json文本对象
@RequestMapping("/favor")
public class favorController {
    @Autowired
    IfavorService favorService;
    //增加
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody favorDTO favorSong){
        favorSong song = favorService.add(favorSong);
        return ResponseMessage.success(song);
    }
    //查询
    @GetMapping("/{musicId}")
    public ResponseMessage get(@PathVariable String musicId){
        favorSong song = favorService.getMusicId(musicId);
        return ResponseMessage.success(song);
    }
    //查询所有
    @GetMapping
    public ResponseMessage getAll(){
        Iterable<favorSong> songs = favorService.getALl();
        return ResponseMessage.success(songs);
    }
    //修改
    @PutMapping
    public ResponseMessage edit(@Validated @RequestBody favorDTO favorSong){
        favorSong song = favorService.edit(favorSong);
        return ResponseMessage.success(song);
    }
    //删除歌曲
    @DeleteMapping("{musicId}")
    public ResponseMessage delete(@PathVariable String musicId){
        favorService.deleteMusicId(musicId);
        return ResponseMessage.success(null);
    }
}